<template>
  <div class="table1">
    <div class="btn-wrap">
      
      <a-button type="info" @click="download">导出</a-button>
    </div>
    
  </div>
</template>

<script>
  import { memberList } from '@/api/sjsk/activity/group/detail/mature/table1'
  import { getList } from '@/api/sjsk/activity/group/detail/mature/table3'
  import downloadXlsl from '../../downloadXlsx.js'
  export default {
    data() {
      return {
        loading:false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10
        },
        pageData: {},
        form: {},
        headerData: [],
        memberList: []
      }
    },
    created() {
      
      
    },
    computed: {
      columns() {
        let columns = [{
            title: '组员名称',
            dataIndex: 'memberName',
            width: 80,
            align: 'center',
            customRender: text => {
              return <j-ellipsis value={text} length={14} />
            }
        }]
        this.headerData.map(item => {
          columns.push({
            title: item.headerName,
            dataIndex: `${item.relateKey}`,
            width: 80,
            align: 'center',
            customRender: text => {
              return <j-ellipsis value={text} length={14} />
            }
          }) 
        })
        this.columns.push({
          title: '最新提交日期',
          align: 'center',
          dataIndex: 'updateTime',
        })
        this.columns.push({
          title: '操作',
          width: 120,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
        return this.data 
      }
    },
    methods: {
      download() {
        downloadXlsl(this.$route.query.id, 10)
      },
      getMemberList() {
        memberList({activityId: this.$route.query.id}).then(res => {
          if(res.success) {
            this.memberList = res.result.records
          }
        })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = {
          currentPage: 'pageNo'
        }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        let form = Object.assign({}, this.queryParam, this.pageFilter)
        form.activityId = this.$route.query.id
        this.loading = true
        getList(form).then((res) => {
            if (res.success) {
              this.pageData = res.result.record
              this.headerData = res.result.unitTableHeaders
              
              this.loading = false
              this.$refs.table.onClearRowKeys()
            } else {
              this.loading = false
            }
          })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
    }
  }
</script>

<style lang="less" scoped>
  .table1 {
    box-sizing: border-box;
    padding: 20px 30px;
    .btn-wrap{
      margin-bottom: 20px;
    }
  }
</style>
